package cn.com.se.sharepictrue.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.List;

import cn.com.se.sharepictrue.R;
import cn.com.se.sharepictrue.bean.BaseUser;
import cn.com.se.sharepictrue.bean.HomeShareBean;
import cn.com.se.sharepictrue.business.ImageLoader;
import cn.com.se.sharepictrue.quickadapter.BaseAdapterHelper;
import cn.com.se.sharepictrue.quickadapter.MultiViewTypeSupport;
import cn.com.se.sharepictrue.quickadapter.QuickAdapter;
import cn.com.se.sharepictrue.utils.StringUtils;

/**
 * Created by KIDNG on 2015/12/5.
 */
public class ConcernAdapter extends QuickAdapter<BaseUser> {
    private Context mContext;

    public ConcernAdapter(Context context, int layoutResId) {
        super(context, layoutResId);
        mContext = context;
    }

    public ConcernAdapter(Context context, int layoutResId, List<BaseUser> data) {
        super(context, layoutResId, data);
        mContext = context;
    }

    public ConcernAdapter(Context context, List<BaseUser> data, MultiViewTypeSupport<BaseUser> multiViewTypeSupport) {
        super(context, data, multiViewTypeSupport);
        mContext = context;
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, final BaseUser item) {
        if(!StringUtils.isEmpty(item.getAvatar())){
            ImageLoader.getInstance(mContext).load((ImageView) (helper.getView(R.id.civ_person_list_avatar)),item.getAvatar(),R.mipmap.ic_follower);
        }
        Button concern = helper.getView(R.id.btn_person_list_concern);
        if (!item.isConcern()) {
            //未关注
            concern.setSelected(false);
            concern.setText(mContext.getResources().getString(R.string.person_list_no_concern));
        } else {
            //已关注
            concern.setSelected(true);
            concern.setText(mContext.getResources().getString(R.string.person_list_concerned));
        }
        concern.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mConcernListener!=null){
                    mConcernListener.toConcern((Button) v,item);
                }
            }
        });
        helper.setText(R.id.tv_person_list_name, item.getUserName());
        helper.setText(R.id.tv_person_list_introduction, item.getSignature());
    }

    public void setConcernListener(toConcernListener concernListener) {
        mConcernListener = concernListener;
    }

    private toConcernListener mConcernListener;
    public interface toConcernListener{
        void toConcern(Button btn, BaseUser item);
    }
}
